package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类管理")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    @ApiOperation("新增分类")
    public Result<Object> addCategory(@RequestBody CategoryDTO categoryDTO) {
        log.info("add category:{}",categoryDTO);
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("pageQuery category:{}",categoryPageQueryDTO);
        return Result.success(categoryService.pageQuery(categoryPageQueryDTO));

    }

    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public  Result<List<Category>> getCategoryByType(Integer type) {
        log.info("getCategoryByType type:{}",type);
        List<Category> categoryList = categoryService.getCategoryByType(type);
        return Result.success(categoryList);
    }
}
